package daam.main;

import java.util.LinkedList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class GameView extends View {

	private final static int MARGEM_FUNDO = 80;
	private Drawable BackgroundImage;
	private Game game;
	private Posicao hunter_pos;
	private Hunter hunter;
	private LinkedList<Elemento> elementos;
	private Bitmap heart = BitmapFactory.decodeResource(this.getResources(),R.drawable.heart);

	public GameView(Context context) {

		super(context);
		this.game = (Game) context;
		
		setFocusable(true);
		
		BackgroundImage = context.getResources().getDrawable(R.drawable.background_level1);	
		setBackgroundDrawable(BackgroundImage);	
		
		
	}

	protected void onDraw (Canvas canvas){
		
		if(hunter !=null)
			canvas.drawBitmap(hunter.getImage(), hunter.getPosicao().getX(), hunter.getPosicao().getY(), new Paint());

		if(elementos!=null){
			for(Elemento e:elementos)
				canvas.drawBitmap(e.getImage(), e.getPosicao().getX(), e.getPosicao().getY(), new Paint());
		}
		
		Paint p = new Paint();
		p.setColor(Color.BLACK);
		p.setTextSize(16);
		p.setFakeBoldText(true);
		p.setShadowLayer(5, 0, 0, Color.BLACK);
		
		canvas.drawText("Pont: "+game.getPontuacao(), 20, 30,p);

		canvas.drawBitmap(heart, canvas.getWidth() - 80, 10, new Paint());
		canvas.drawText(" X "+game.getVidas(), canvas.getWidth() - 50, 30, p);
	}
	
	public void paint(Hunter hunter, LinkedList<Elemento> elementos){

		this.hunter = hunter;
		this.elementos = elementos;

		invalidate();			

	}

	public Posicao getPosicao(){
		return hunter_pos;
	}

	public boolean onTouchEvent (MotionEvent event){

		return true;

	}

	public void desenha() {
		invalidate();
	}

}

